package io.renren.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.entity.SysOrderEntity;
import io.renren.entity.SysReturnGoodsEntity;
import io.renren.entity.SysReturnGoodsOperationEntity;
import io.renren.service.SysReturnGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 *
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-14 11:22:39
 */
@RestController
@RequestMapping("api/sysreturngoods")
@Api(tags = "退货")
public class SysReturnGoodsController {
    @Autowired
    private SysReturnGoodsService sysReturnGoodsService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("查询退货订单")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysReturnGoodsService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 同意退款、立即退款=====同意退货（修改状态）
     * @param  id 订单id
     */
    @GetMapping("/refund/{id}")
    @ApiOperation("商家同意退款")
    public R argessRefund(@PathVariable("id") Integer id,@RequestParam("type") Integer type){
        sysReturnGoodsService.argessRefundOrGoods(id,type);
        return R.ok();
    }

    /**
     * 拒绝退款
     */
    @PostMapping("/rejectRefund")
    @ApiOperation("拒绝退款")
    public R rejectRefund(@RequestBody SysReturnGoodsOperationEntity sysReturnGoodsOperationEntity){
        sysReturnGoodsService.rejectRefund(sysReturnGoodsOperationEntity);
     return R.ok();
}

    /**
     * 拒绝退货
     */
    @PostMapping("/rejectGoods")
    @ApiOperation("拒绝退货")
    public R rejectGoods(@RequestBody SysReturnGoodsOperationEntity sysReturnGoodsOperationEntity){
        sysReturnGoodsService.rejectGoods(sysReturnGoodsOperationEntity);
        return R.ok();
    }

    /**
     * 查询订单信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("根据ID查询退货信息")
    public R info(@PathVariable("id") Integer id){
        SysOrderEntity sysReturnGoods=sysReturnGoodsService.selectById(id);
        return R.ok().put("sysReturnGoods", sysReturnGoods);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加")
    public R save(@RequestBody SysReturnGoodsEntity sysReturnGoods){
        sysReturnGoodsService.save(sysReturnGoods);

        return R.ok();
    }

    @GetMapping("/emitOrder/{id}")
    @ApiOperation("确认收货")
    public  R emitGoods(@PathVariable("id")Integer id){
        sysReturnGoodsService.emitGoods(id);
        return R.ok();
    }

//
//    /**
//     * 删除
//     */
//    @DeleteMapping("/delete")
//    @ApiOperation("根据ID删除")
//    public R delete(@RequestBody Integer[] ids){
//        sysReturnGoodsService.removeByIds(Arrays.asList(ids));
//
//        return R.ok();
//    }
//
//    /**
//     * 同意取消订单
//     */
//    @PostMapping("/agree")
//    @ApiOperation("同意取消订单")
//    public R agree(Integer id, Boolean state){
////        ValidatorUtils.validateEntity(sysReturnGoods);
//        sysReturnGoodsService.agree(id, state);
////        sysReturnGoodsService.updateById(sysReturnGoods);
//
//        return R.ok();
//    }
//
//    /**
//     * 查询商户退货单
//     */
//    @GetMapping("/queryMerchantReturn/{id}")
//    @ApiOperation("查询商户退货单")
//    public R queryMerchantReturn(@PathVariable Integer id, @RequestParam Map<String, Object> params) {
//        PageUtils pageUtils = sysReturnGoodsService.queryByRetailOrMerchantId(id, 2, params);
//        return R.ok().put("page", pageUtils);
//    }
//
//    /**
//     * 查询门户退货单
//     */
//    @GetMapping("/queryRetailReturn/{id}")
//    @ApiOperation("查询门户退货单")
//    public R queryRetailReturn(@PathVariable Integer id, @RequestParam Map<String, Object> params) {
//        PageUtils pageUtils = sysReturnGoodsService.queryByRetailOrMerchantId(id, 1, params);
//        return R.ok().put("page", pageUtils);
//    }
//
//    /**
//     * 退货单详情
//     */
//    @GetMapping("/detail/{id}")
//    @ApiOperation("退货单详情")
//    public R  queryDetailById(@PathVariable Integer id) {
//        SysReturnGoodsEntity sysOrder = sysReturnGoodsService.queryDetailById(id);
//
//        return R.ok().put("order", sysOrder);
//    }
//
//    /**
//     * 商户确认退货收货
//     */
//    @PostMapping("/merchant/confimReceipt")
//    @ApiOperation("商户确认退货收货")
//    public R confimReceipt(@RequestBody SysReturnGoodsEntity sysReturnGoodsEntity) {
//        sysReturnGoodsService.confimReceipt(sysReturnGoodsEntity);
//
//        return R.ok();
//    }
//
//    /**
//     * 客户点击发货(退货)
//     */
//    @PostMapping("/user/returnGoods")
//    @ApiOperation("客户点击发货(退货)")
//    public R returnGoods(@RequestBody SysReturnGoodsEntity sysReturnGoodsEntity) {
//        sysReturnGoodsService.returnGoods(sysReturnGoodsEntity);
//
//        return R.ok();
//    }
}
